<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>途损编辑</title>
<link href="/resources/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="/resources/lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="/resources/lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="/resources/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>
<script src="/resources/lib/jquery-validation/jquery.validate.min.js" type="text/javascript"></script> 
<script src="/resources/lib/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
<script src="/resources/lib/jquery-validation/messages_cn.js" type="text/javascript"></script>
<script src="/resources/lib/json2.js" type="text/javascript"></script>
<script src="/resources/js/jsF7.js" type="text/javascript"></script>
<script src="/resources/js/selectData.js" type="text/javascript"></script>
<script src="/resources/js/themis.js" type="text/javascript"></script>
<script src="/resources/js/validation.js" type="text/javascript"></script>

<script type="text/javascript">
	var grid;
	$(function(){
	    //工具条
	    $("#toptoolbar").ligerToolBar({ items: [
	        	{ text: '保存', id:'save',click: saveForm,icon: 'save' }
	    	]
	    });
        //创建分录
        grid = $("#grid").ligerGrid({
            columns: [
          	        { display: '商品编码', name: 'material.uuid', type: 'popup', width: 100,textField:'material.number',
        	          	editor: {
                         grid: getMaterialGrid(true),
                         valueField: 'uuid',
                         textField: 'number',
                         parms :{date:new Date().getTime()},
                         width: 300,
                         height:100,
                         realTimeLoad:true,
                	  }
        	        },
            	{ display: '商品名称', name: 'materialName', width: 150,type: 'text'},
        	    { display: '途损数量', name: 'lossQty', width: 150,editor: {type: 'float'}},
        	    { display: '途损金额', name: 'lossAmount', width: 150,editor: {type: 'float'}},
        	    { display: '处理方式', name: 'processMode', width: 150,editor: {type: 'select',data:getLossTypeSelect()}},
        	    { display: 'resourceId', name: 'resourceId', hide:true, width: 100, type: 'text' },
        	    { display: 'resourceEntryId', name: 'resourceEntryId', hide:true, width: 100, type: 'text' },
    	        { display: 'uuid',name: 'uuid',width: 100,hide:true, type: 'text' }
            ], usePager: false,width: '95%',height: '400px',enabledEdit: true,alternatingRow:true,
            checkbox: true,headerRowHeight:22, rowHeight:22, rownumbers:true,
            url:'/loss/listData?parentId=${parentId}',
/*             toolbar: { items: [
                               { text: '添加行', click: addNewRow,icon: 'add' },
                               { line: true },
                               { text: '删除行', click: delRow,icon: 'delete' }
                               ]
                     } */
            
        });
	});
</script>
</head>
<body>
  <div id="toptoolbar"></div>
  <div id="grid" style="margin-top:15px;margin-left: 15px;"></div>
</body>
<script type="text/javascript">
var parentId = '${parentId}';
//添加分录
function addNewRow(){
	grid.addRow({ 
		parentId:parentId,
		lossQty:"0.00",
		lossAmount:"0.00"
    });
}
//删除分录
function delRow(){
	grid.deleteSelectedRow();
}
//保存
function saveForm(){
		var delData = grid.getDeleted();
		var gridData = grid.getData();
		$.ajax({
	        loading: '正在保存数据中...',
	        type:'post',
	        url: "/loss/saveOrUpdateLoss",
			dataType:'json',
	        data: {gridData:JSON.stringify(gridData)},
	        success: function (data) {
					$.ligerDialog.success(data.message,'信息',function(){
						grid.reload();
				    });
	        },
	        error: function (message) {
	       	 	$.ligerDialog.error("保存失败");
	        }
	    });
   }
</script>
</html>
